package com.imoocdl.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * Created by pc on 2018/7/19.
 */
@RestController
@Slf4j
@RequestMapping(value = "/weixin")
public class WeixinContorller {
    /**
     * 微信同意授权后 会携带code参数 进入该方法
     */
    @GetMapping("/auth")
    public void auth(@RequestParam(value = "code") String code){
        log.info("code={}",code);
        log.info("进入author方法.............");
        //获取openid
        String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx9aca515824006c60&secret=7a64f525b6e545139d073674b8e8de36&code="+code+"E&grant_type=authorization_code";
        RestTemplate restTemplate = new RestTemplate();
        String response = restTemplate.getForObject(url,String.class);
        log.info("response={}",response);
    }
}
